setwd("/scratch/jc227089/evostochPBS/")


h2H<-seq(0.1, 1, 0.3)
h2D<-seq(0.1, 1, 0.3)
pop.reps<-10

script.file<-"/home/jc227089/scratch/evo-dispersal/evostoch/evostoch_h2walker.R"
fname<-"evostoch"
for (kk in 1: length(h2H)){
	for (jj in 1:length(h2D)){
		for (ii in 1:pop.reps) {

			fid<-paste(h2D[jj]*10, h2H[kk]*10, ii, sep="_")
			##create the sh file
			zz = file(paste(fname, fid,'.sh',sep=''),'w')
			cat('##################################\n',file=zz)
			cat('#!/bin/sh\n',file=zz)
			cat('cd $PBS_O_WORKDIR\n',file=zz)
			cat('module load R\n', file=zz)
			cat("R CMD BATCH --no-save --no-restore '--args repn=",ii, " h2H=",h2H[kk], " h2D=",h2D[jj], "' ", sep="", file=zz)
			cat(script.file, " ", paste(fname, fid,'.Rout',sep=''), "\n", sep="",file=zz)
			cat('##################################\n',file=zz)
			close(zz)
				
			#submit the job
			system(paste("qsub -m n ", paste(fname, fid,".sh",sep=""),sep=""))
		}
	}
}
